package com.liuzh.deviceinfo;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.res.Resources;
import android.database.DataSetObserver;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.VelocityTracker;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.p;
import androidx.recyclerview.widget.RecyclerView.z;
import androidx.viewpager.widget.ViewPager;
import b.l.a.o;
import b.p.b.q;
import c.h.a.b0.l;
import c.h.a.f0.j;
import c.h.a.j0.h0;
import c.h.a.j0.u0;
import c.h.a.m0.h;
import c.h.a.m0.i;
import com.google.android.material.tabs.TabLayout;
import com.liuzh.deviceinfo.base.BaseActivity;
import com.liuzh.deviceinfo.pro.ProActivity;
import com.liuzh.deviceinfo.settings.SettingsActivity;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

public class MainActivity extends BaseActivity implements c.h.a.f0.j.a {
    public static final /* synthetic */ int y = 0;
    public ViewPager q;
    public TabLayout r;
    public ArrayList<h0> s;
    public int t = h.t(10.0f, DeviceInfoApp.c.getResources().getDisplayMetrics());
    public MainActivity u = this;
    @SuppressLint({"InflateParams"})
    public OnLongClickListener v = new a();
    public o w;
    public LinearLayout x;

    public class a implements OnLongClickListener {
        public boolean onLongClick(View view) {
            int indexOfChild = ((ViewGroup) view.getParent()).indexOfChild(view);
            PopupWindow popupWindow = new PopupWindow(MainActivity.this.u);
            View inflate = LayoutInflater.from(MainActivity.this).inflate(2131493037, null);
            TextView textView = (TextView) inflate.findViewById(2131296456);
            textView.setText(MainActivity.this.getString(2131689754, new Object[]{((h0) MainActivity.this.s.get(indexOfChild)).r0()}));
            textView.setOnClickListener(new c.h.a.c(this, indexOfChild, popupWindow));
            ((TextView) inflate.findViewById(2131296337)).setOnClickListener(new c.h.a.a(this, popupWindow));
            ((TextView) inflate.findViewById(2131296977)).setOnClickListener(new c.h.a.b(this, popupWindow));
            popupWindow.setContentView(inflate);
            popupWindow.setFocusable(true);
            popupWindow.setOutsideTouchable(true);
            popupWindow.setBackgroundDrawable(new ColorDrawable(0));
            popupWindow.showAsDropDown(view, 0, -MainActivity.this.t);
            return true;
        }
    }

    public class c extends DataSetObserver {
        public void onChanged() {
            MainActivity mainActivity = MainActivity.this;
            int i = MainActivity.y;
            mainActivity.B();
        }
    }

    public class d implements Runnable {
        public void run() {
            c.h.a.l0.b bVar = c.h.a.l0.b.b;
            MainActivity mainActivity = MainActivity.this.u;
            c.h.a.l0.a aVar = bVar.a;
            if (aVar != null) {
                aVar.a(mainActivity);
            }
            MainActivity mainActivity2 = MainActivity.this.u;
            boolean z = h.a;
        }
    }

    public class e implements Runnable {
        public void run() {
            c.a.a.g.b(MainActivity.this.getApplicationContext(), "lottie/file_analyzing.json");
        }
    }

    public class g extends androidx.recyclerview.widget.RecyclerView.e<a> {
        public LayoutInflater c;
        public q d;

        @SuppressLint({"ClickableViewAccessibility"})
        public class a extends z {
            public ImageView t;
            public TextView u = ((TextView) this.a.findViewById(2131296753));

            public a(View view) {
                super(view);
                this.t = (ImageView) view.findViewById(2131296729);
                this.t.setOnTouchListener(new c.h.a.e(this));
            }
        }

        public g(q qVar) {
            this.d = qVar;
        }

        public int a() {
            return MainActivity.this.s.size();
        }

        public void f(z zVar, int i) {
            ((a) zVar).u.setText(((h0) MainActivity.this.s.get(i)).r0());
        }

        public z g(ViewGroup viewGroup, int i) {
            if (this.c == null) {
                this.c = LayoutInflater.from(viewGroup.getContext());
            }
            return new a(this.c.inflate(2131492994, viewGroup, false));
        }
    }

    public class b extends o {
        public b(b.l.a.h hVar, int i) {
            super(hVar, i);
        }

        public int c() {
            return MainActivity.this.s.size();
        }

        public int d(Object obj) {
            return -2;
        }

        public CharSequence e(int i) {
            return ((h0) MainActivity.this.s.get(i)).r0();
        }
    }

    public class f extends c.h.a.n0.i.a {
        public f() {
            super(MainActivity.this.s);
        }

        public void a(RecyclerView recyclerView, z zVar) {
            zVar.a.setPressed(false);
            if (this.d) {
                MainActivity mainActivity = MainActivity.this;
                int i = MainActivity.y;
                mainActivity.E();
            }
        }
    }

    public final void A() {
        if (this.s.size() >= 20) {
            Toast.makeText(this, getString(2131690516, new Object[]{Integer.valueOf(20)}), 0).show();
            return;
        }
        List a = u0.a();
        ArrayList arrayList = new ArrayList();
        Iterator it = ((ArrayList) a).iterator();
        while (it.hasNext()) {
            arrayList.add(((c.h.a.j0.u0.b) it.next()).b);
        }
        b.b.c.f.a aVar = new b.b.c.f.a(this.u);
        aVar.e(2131689513);
        CharSequence[] charSequenceArr = (CharSequence[]) arrayList.toArray(new CharSequence[0]);
        c.h.a.d dVar = new c.h.a.d(this, a);
        androidx.appcompat.app.AlertController.b bVar = aVar.a;
        bVar.p = charSequenceArr;
        bVar.r = dVar;
        aVar.g();
    }

    public final void B() {
        this.r.setupWithViewPager(this.q);
        if (this.r.getChildCount() > 0) {
            int i = 0;
            ViewGroup viewGroup = (ViewGroup) this.r.getChildAt(0);
            int childCount = viewGroup.getChildCount();
            while (i < childCount) {
                viewGroup.getChildAt(i).setOnLongClickListener(this.v);
                i++;
            }
        }
    }

    public void C(Class<? extends h0> cls) {
        int i = 0;
        while (i < this.s.size()) {
            if (((h0) this.s.get(i)).getClass() == cls) {
                break;
            }
            i++;
        }
        i = -1;
        if (i != -1) {
            this.q.v(i, true);
        }
    }

    public final void D(int i) {
        if (this.s.size() == 1) {
            Toast.makeText(this.u, getString(2131690043, new Object[]{Integer.valueOf(1)}), 0).show();
            return;
        }
        this.s.remove(i);
        b.u.a.a adapter = this.q.getAdapter();
        if (adapter != null) {
            adapter.h();
        }
        E();
    }

    public final void E() {
        ArrayList arrayList = new ArrayList();
        Iterator it = this.s.iterator();
        while (it.hasNext()) {
            arrayList.add(u0.b.get(((h0) it.next()).getClass()));
        }
        i iVar = i.a;
        iVar = i.a;
        StringBuilder stringBuilder = new StringBuilder();
        Iterator it2 = arrayList.iterator();
        while (it2.hasNext()) {
            stringBuilder.append(((c.h.a.j0.u0.b) it2.next()).c);
            stringBuilder.append("#");
        }
        stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        i.b.edit().putString("custom_tabs", stringBuilder.toString()).apply();
    }

    public final void F(boolean z) {
        if (z) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(getString(2131689568));
            stringBuilder.append(" ");
            stringBuilder.append(getString(2131690189));
            setTitle(stringBuilder.toString());
            return;
        }
        setTitle(2131689568);
    }

    @SuppressLint({"InflateParams"})
    public final void G() {
        RecyclerView recyclerView = (RecyclerView) LayoutInflater.from(this).inflate(2131492959, null);
        q qVar = new q(new f());
        recyclerView.setAdapter(new g(qVar));
        RecyclerView recyclerView2 = qVar.r;
        if (recyclerView2 != recyclerView) {
            if (recyclerView2 != null) {
                recyclerView2.f0(qVar);
                recyclerView2 = qVar.r;
                p pVar = qVar.A;
                recyclerView2.p.remove(pVar);
                if (recyclerView2.q == pVar) {
                    recyclerView2.q = null;
                }
                List list = qVar.r.C;
                if (list != null) {
                    list.remove(qVar);
                }
                for (int size = qVar.p.size() - 1; size >= 0; size--) {
                    qVar.m.a(qVar.r, ((b.p.b.q.f) qVar.p.get(0)).e);
                }
                qVar.p.clear();
                qVar.w = null;
                qVar.x = -1;
                VelocityTracker velocityTracker = qVar.t;
                if (velocityTracker != null) {
                    velocityTracker.recycle();
                    qVar.t = null;
                }
                b.p.b.q.e eVar = qVar.z;
                if (eVar != null) {
                    eVar.a = false;
                    qVar.z = null;
                }
                if (qVar.y != null) {
                    qVar.y = null;
                }
            }
            qVar.r = recyclerView;
            Resources resources = recyclerView.getResources();
            qVar.f = resources.getDimension(2131165336);
            qVar.g = resources.getDimension(2131165335);
            qVar.q = ViewConfiguration.get(qVar.r.getContext()).getScaledTouchSlop();
            qVar.r.g(qVar);
            RecyclerView recyclerView3 = qVar.r;
            recyclerView3.p.add(qVar.A);
            recyclerView3 = qVar.r;
            if (recyclerView3.C == null) {
                recyclerView3.C = new ArrayList();
            }
            recyclerView3.C.add(qVar);
            qVar.z = new b.p.b.q.e();
            qVar.y = new b.i.k.d(qVar.r.getContext(), qVar.z);
        }
        b.b.c.f.a aVar = new b.b.c.f.a(this);
        aVar.e(2131690391);
        androidx.appcompat.app.AlertController.b bVar = aVar.a;
        bVar.t = recyclerView;
        bVar.s = 0;
        bVar.n = new c.h.a.f(this);
        aVar.g();
    }

    public void i(boolean z) {
        invalidateOptionsMenu();
        F(z);
    }

    public void onBackPressed() {
        if (!((h0) this.s.get(this.q.getCurrentItem())).n0()) {
            this.e.a();
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(2131492893);
        Toolbar toolbar = (Toolbar) findViewById(2131297061);
        toolbar.setOverflowIcon(getDrawable(2131231049));
        s().x(toolbar);
        LinearLayout linearLayout = (LinearLayout) findViewById(2131296714);
        this.x = linearLayout;
        linearLayout.setVisibility(8);
        F(j.d.i());
        i iVar = i.a;
        iVar = i.a;
        List a;
        if (h.p()) {
            a = u0.a();
        } else {
            String string = i.b.getString("custom_tabs", null);
            if (string == null) {
                a = u0.a();
            } else {
                String[] split = string.split("#");
                ArrayList arrayList = new ArrayList();
                for (Object obj : split) {
                    arrayList.add(u0.c.get(obj));
                }
                a = arrayList;
            }
        }
        this.s = new ArrayList();
        for (c.h.a.j0.u0.b bVar : a) {
            try {
                this.s.add(bVar.a.newInstance());
            } catch (IllegalAccessException | InstantiationException unused) {
            }
        }
        this.q = (ViewPager) findViewById(2131297333);
        b bVar2 = new b(o(), 1);
        this.w = bVar2;
        this.q.setAdapter(bVar2);
        this.r = (TabLayout) findViewById(2131297015);
        B();
        this.w.a.registerObserver(new c());
        iVar = i.a;
        iVar = i.a;
        if (i.b() && i.a()) {
            new l(this).b();
            c.b.a.a.a.p(i.b, "close_ad_show_donate", false);
        }
        j.d.h(this);
        this.q.post(new d());
        AsyncTask.execute(new e());
        c.h.a.v.a.b.c("home_open", null);
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        j jVar = j.d;
        if (!jVar.i()) {
            Objects.requireNonNull(jVar);
            menu.add(0, 5, 0, 2131690189).setShowAsActionFlags(2).setIcon(2131231054);
        }
        menu.add(0, 1, 9, 2131690339).setShowAsActionFlags(2).setIcon(2131231078);
        if (!h.p()) {
            menu.add(0, 2, 10, 2131689753).setShowAsActionFlags(0);
            menu.add(0, 3, 11, 2131689513).setShowAsActionFlags(0);
            menu.add(0, 4, 12, 2131690391).setShowAsActionFlags(0);
        }
        return super.onCreateOptionsMenu(menu);
    }

    public void onDestroy() {
        super.onDestroy();
        j.d.j(this);
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId == 1) {
            startActivity(new Intent(this, SettingsActivity.class));
            return true;
        } else if (itemId == 2) {
            D(this.q.getCurrentItem());
            return true;
        } else if (itemId == 3) {
            A();
            return true;
        } else if (itemId == 4) {
            G();
            return true;
        } else if (itemId != 5) {
            return super.onOptionsItemSelected(menuItem);
        } else {
            ProActivity.F(this.u);
            return true;
        }
    }

    public void onResume() {
        super.onResume();
        i iVar = i.a;
        iVar = i.a;
        if (i.b()) {
            this.x.setVisibility(8);
        }
    }

    public boolean y() {
        return false;
    }
}
